
#ifndef GLWIDGET_H
#define GLWIDGET_H
#include <QGLWidget>
#include <QSound>

#define LINE 1
#define TEXTURED 2

class GLWidget : public QGLWidget
{
    Q_OBJECT

public:
    bool showSky;
    bool showMap;
    bool showFog;
    int renderType;
    float density;
    GLWidget(QWidget *parent = 0);
    ~GLWidget();

    void onTimer();

    void initializeGL();
    void initSkyTexture(bool msg=true);
    void initHeightMap(bool msg=true);
    void initHeightMapTexture(bool msg=true);
    void initTrees(bool msg=true);


    void drawSky();
    void drawTrees();
    void genHeightMapList();
    void loadSettings();
    void saveSettings();
    void setSkyTex();
    void setHMapTex();
    void setHMapRaw();

    QString getSkyTex();
    QString getHMapTex();
    QString getHMapRaw();
    void orientMe(float ang);
    void moveMeFlat(int i);
    void Lookup(int i);
    void setFog(bool enable);
    void setFogDensity(int dens);
protected:
    void paintGL();
    void resizeGL(int width, int height);

    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);

    void keyEv(QKeyEvent * e);
    void keyPressEvent(QKeyEvent *e);
    void keyReleaseEvent(QKeyEvent *e);

    virtual void enterEvent(QEvent *e);
    virtual void leaveEvent(QEvent *);
private:
    QPoint lastPos;
    QString skyTex;
    QString hMapTex;
    QString hMapRaw;
    QString treeTex;

    float fogColor[4];

    void enableCullingMode(bool value);
    void setLightning();
    int height(unsigned char* pHeightMap, int X, int Y);
    void setVertexColor(unsigned char* pHeightMap, int x, int y);
    void getRightVector(float *right);

};


#endif
